package com.example.userregister;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button btnRegister;
    private EditText etName;
    private EditText etPsw;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnRegister = (Button) findViewById(R.id.btn_register);
        etName = (EditText) findViewById(R.id.et_name);
        etPsw = (EditText) findViewById(R.id.et_psw);
        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击按钮，跳转到详情页面，将输入的name和password传递给详情页面
                //显示意图
                Intent intent = new Intent(MainActivity.this,ShowInfoActivity.class);
                //数据放入intent，通过intent传递数据给下一页
                String name ;
                String password;
                //用户名和密码非空进行跳转
                if(etName.length()==0||etPsw.length()<=0){
                    //空
                    Toast.makeText(MainActivity.this,"用户名和密码不能为空",Toast.LENGTH_LONG).show();
                }else{
                    //非空
                    name = etName.getText().toString();
                    password = etPsw.getText().toString();
                    //key，value
                    intent.putExtra("username",name);
                    intent.putExtra("password",password);
                    startActivity(intent);
                }
            }
        });

    }
}
